﻿using System;
using System.Collections.Generic;
using System.Reflection;
using System.Text;

namespace ConsoleAuth
{
    class Program
    {
        static void Main(string[] args)
        {
            var arguments = Common.CommandLineArgumentParser.Parse(args);

            if (arguments.Has("-u"))
            {
                Console.WriteLine("用户名：{0}", arguments.Get("-u").Next);
            }

            if (arguments.Has("-p"))
            {
                Console.WriteLine("密码：{0}", arguments.Get("-p").Next);
            }

            Console.WriteLine("run");

            var consoleFunType = typeof(ConsoleFun);
            while (true)
            {
                var cmd = Console.ReadLine();

                //switch(cmd)
                //{
                //    case "OpenForm":
                //        openForm();
                //        break;
                //}

                var method = consoleFunType.GetMethod(cmd, BindingFlags.Public| BindingFlags.IgnoreCase|BindingFlags.Static);

                if (method == null)
                {
                    Common.ConsoleHelper.ShowError("找不到对应的方法");
                    continue;
                }

                var attr = method.GetCustomAttributes(typeof(ColsoleMethod), false);

                if(attr.Length<=0)
                {
                    Common.ConsoleHelper.ShowError("找不到对应的方法");
                    continue;
                }

                method.Invoke(null, null);
            }
        }
    }
}
